package com.ruirui.demo;

import reactor.core.publisher.Flux;
import reactor.core.publisher.FluxSink;

/**
 * 多线程创建
 */
public class FluxCreate {
    public static void main(String[] args) {

        Flux.create(sink -> {
            MyListener myListener = new MyListener(sink);
            for (int i = 0; i < 10; i++) {
                myListener.onLine("name" + i);
            }
            sink.complete();
        }).subscribe();
    }
}
//监听线程
class MyListener{
    FluxSink<Object> sink;

    public MyListener(FluxSink<Object> sink) {
        this.sink = sink;
    }

    public void onLine(String name){
      System.out.println(name +" :上线了");
      sink.next(name);
  }
}